package com.abhi.webservices.controller;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;

import com.abhi.webservices.services.RestTestServices;

import web.login.controller.ForgotPasswordController;
import web.login.entity.Login;

@Controller
public class RestTestController {

	private final Log log = LogFactory.getLog(RestTestController.class);
	
	@Autowired
	private RestTestServices restTestServices;
	
	@Autowired
	private View jsonView_i;
	
	private static final String DATA_FIELD = "data";
	private static final String ERROR_FIELD = "error";


	@RequestMapping(value="/restJson.htm", method = RequestMethod.GET)
	public ModelAndView onload() {  
	        
	        return new ModelAndView("restJson");  
       }  

  
	
	@RequestMapping(value="/logins", method = RequestMethod.GET)
	public ModelAndView getFunds() {  
	        List<Login> logins = null;  
	
	        try 
	        {  
	        	log.info("INSIDE REST TEST CONTROLLER ::: ");
	        	logins = this.restTestServices.getAllLogins();  
	        }
	        catch (Exception e) 
	        {  
	        	log.info("INSIDE REST TEST CONTROLLER ::: Exception Occurred ~~~ ");
	        	e.printStackTrace();
	        }  
	
	        log.info("Returing Funds: " + logins.toString());  
	        return new ModelAndView(jsonView_i, DATA_FIELD, logins);  
       }  

  
}
